<template>
  <van-form @submit="onSubmit">
    <van-field label="账号" readonly v-model="user.id"></van-field>
    <van-field label="用户名" v-model="user.name" type="text"></van-field>
    <van-field label="原始密码" v-model="user.oldpwd" type="password"
    :rules="[{ pattern:regNamePwd,require:true,message:'密码格式错误！'}]"
    ></van-field>
    <van-field label="新的密码" v-model="user.pwd" type="password"
    :rules="[{ pattern:regNamePwd,require:true,message:'密码格式错误！'}]"
    ></van-field>
    <van-field label="确认密码" v-model="user.ispwd" type="password"
    :rules="[{ pattern:regNamePwd,require:true,message:'密码格式错误！'}]"
    ></van-field>
    <van-button round block type="info" native-type="submit">提交</van-button>
  </van-form>
</template>

<script>
  export default{
    data(){
      return{
        user:{
          id:null,
          name:"",
          oldpwd:"",
          pwd:"",
          ispwd:""
        },
        regNamePwd: /^[a-z0-9]{3,12}$/i,

      }
    },
    methods:{
      onSubmit(){
        if(this.user.id==null){
          this.$toast("用户id不能为空");
          return;
        }
        if(this.user.name===""){
          this.$toast("用户名不能为空");
           return;
        }
        if(this.user.oldpwd===""){
          this.$toast("原始密码为空");
           return;
        }
        if(this.user.pwd===""){
          this.$toast("新密码为空");
           return;
        }
        if(this.user.ispwd===""){
          this.$toast("新密码为空");
           return;
        }
        if(this.user.ispwd!=this.user.pwd){
          this.$toast("两次密码不一致");
           return;
        }
      }
    }
  }
</script>

<style>
</style>
